on a busy (darwin) system it's leaving done files around, this is more atomic
use a unique temporary name to avoid conflicts
Merge pull request #1 from quartzjer/master

Be a bit more safe with the temporary files