Another program which you might discover and be tempted to try is EventScripts. Although it is a very impressive program which I would recommend in general, after testing it for this purpose it does NOT actually appear to be able to trigger scripts quickly enough for them to run before your Mac goes to sleep, and instead the sleep script will not run until after the Mac has woken up, which (obviously) defeats the purpose.
I hope to save you and anyone else reading this the hours of testing it took me to come to this conclusion. I'm sorry to have to say that it failed, however, because in so many respects it is a really nicely designed and quite powerful and flexible program. It's also quite inexpensive ($3). The low-level performance just doesn't seem to be there, however, for running a script before sleeping.
On the other hand, in my tests (so far) sleepwatcher has appeared to be quite reliable and fast. It's also free, which is awesome. I'll keep testing and if I find it to not work sometimes I'll update my answer, and keep testing other options.
UPDATE I have not found sleepwatcher to be consistently reliable since originally writing this answer, although it initially appeared to be working. In my case I don't need to run arbitrary scripts, but instead just eject external drives. I've found a small and inexpensive app that does this very well so far: Jettison. This has very quickly become one of a small handful of utilities I can't live without. If your needs are the same as mine, I think you'll find it well worth the few bucks they charge.