In both sh and perl scripts, for files that have the same expected longevity as the script itself, I tend to create temporary files with the creating PID in the filename and then remove these files at the end of the script - either via a trap command or an END block.
A user level that continues to overstate my experience :-))