Most people when they are cooking they create a lot of dirty dishes. They might even leave the dishes in the sink after dinner, but then in the morning they clean up everything because they know when they will want to cook again they need the clean dishes.
This is the same with programming.
You might be in a hurry to implement a feature or fix a bug and push it out to the customers, but then, once you are done you go back and clean up the mess you left because you know that next time you need to change this code you'd like to arrive to a clean environment.
To facilitate a safe refactoring environment you would write tests.