26-03-04 - Create Use and Delete Temp File
How have I only just learnt about mktemp? It's a great way to create a temporary file, and trap means that it is automatically cleaned up when the script exits.
tmpfile=$(mktemp)
trap 'rm -f "$tmpfile"' EXIT