I think this is more about "feature creep" than specifically about code, though the OP's point is well taken. But the distinction matters: the dilemma I find myself facing is: do I write that extra library or test to make sure things work? Do I take the time to refactor? Is it worth the time?
In those situations, it isn't at all an easy question, unless you know the problem you face requires a one-off software solution with little liability for maintenance.