Does the problem only occur when you're writing code at work?
What I mean is if this is work related, perhaps you want check your mental model of the work and the results expected from you.
For example: I spent too much time considering (most of the times unconsciously) what kind of solution is expected and how people would react to it. This sounds like an odd thing to do but it wasn't like I chose to do this. But it was a conscious decision to get rid of it and regain the initial (for lack of a better word) playfulness. And live with the consequences. Somehow it nests easily in a mind that serious work shouldn't be fun and is all about mindlessly meeting requirements. I find that it is important to not let this happen.
So far the results have been pretty good for me.