I suppose it's rather a matter on one's perception about the code and the abilities does he [or she] possess the most.
Code rewrite is not so error prone when you have lots of code to rewrite.
It's a bad a idea to start rewrite when you have more than 30K lines of code.
You will end up with new code that needs to be tested again and you will find yourself "inserting" new bugs and even repeating old mistakes.
If your code is stable and works fine but only has limitations then it is rather good to start Refactoring your code and to do this via continuous integration.
Refactoring and continuous integration will always keep your code compilable, testable and even compatible; you will get accustomed with the code, understand it and even be visionary to what it should become in the future.
But to do that you need to learn about :
1. refactoring (here's a good resource : https://refactoring.guru/refactoring
2. continuous integration ( https://en.wikipedia.org/wiki/Continuous_integration
3. tests writing
It's good to have in mind a programming model that, let's say, you have seen it at older programmers (or more experienced if you wish to call it by name) in their own nice libraries (not giving any names here).
Why invest in writing from scratch, having to care for 2 versions, releasing bug fixes for 2 versions that don't go well with each other ?
Refactoring code keeps your code stable and testable and releaseable at any time because you used continuous integration as way of coding.
Of course a good editor could help a lot (like replace in all files, search in all files, etc, like in NetBeans/PhpStorm or Visual Studio - more or less).
Writing tests for your code is also a good idea, since refactoring (like moving a standalone function from global context to being a [static] method on a class) done in a hurry could have left some parts of your code unattended and so you could have broke some functionalities.But if you don't like refactoring and code rewrite is much easier for you
and you know that you will have time to rewrite, test and release your code than perhaps refactoring is not for you ...
Anyway, refactoring also includes code rewrite but only where its suited :) so you should still read about refactoring (and continous integration (and testing))