Improved handling of temporary files: always use system temp directory
and delete files after usage.