in reply to Does anybody write tests first?
What helped is to move the functionality to modules, because IMHO modules are much neater to test than scripts.
So I started to write modules that do 95% of the work, and the scripts that use these modules just do some command line processing, but no real logic.
And yes, often I write the tests first. That's especially useful if you have a small, complex piece of code. Like a recursive regex that parses nested constructs.
Then you can build a basic regex, run the tests, refine it, run the tests, ... until you're done. And you don't fall into the trap of modifying something and getting what you want, but having undetected side effects. (At least you're not trapped that easily ;)