Improved temp. file handling using mktemp