I like to use the (nowadays) builtin
File::Temp module for that. It allows you to ask for temporary files (and whole directory trees) that get autmatically cleaned up and also allows you to portably have these files in an appropiate temporary area so you don't have to assume too much about the writability of the place where the module source resides and is being tested.