File::Temp can be used to create and open temporary files in a safe way
https://metacpan.org/release/File-Temp