We have all run into situations where, while trying to solve a problem, we write a bit too much code. Maybe it is a utility method that it turns out we don't need yet. Maybe it is a possible solution to the problem that we decide against for reasons of performance or readability or style. Maybe it is a line or 5 of printf/testing code that you think might come in handy again. Rationally, we know that this code is very unlikely to be used in the future and is making our code base messier. Emotionally though, it is unpleasant to kill your babies, and it can be very easy to just comment out the code and leave it in place, with the thought that then the code will be there for you in the future when you will surely need it.
One effective way to handle this to keep an extra tab open in your text editor. Whenever you have code that you do not need now (but that will be surely vindicated by history), cut the code out and paste it into this special file. This keeps your code base clean, but is also gentle to your emotions. Your babies are not gone they are just on vacation. Then, a few weeks later when you need to re-start your computer, you can check this file. It will be filled with pages and pages of code that you did not actually need, and you can realize yet again that YAGNI. I've found this to be an effective way to make it easy to make the right decision about leaving extra lines in the code base.