Improved temp file name generation.
Moved temp file unlinking closer to generation.