Fix temporary folder name generation collisions

First, the regular expression matches everything after the first period
in a filename.  Adding the $ make it match the last, so that filenames
such as “Report.1.pdf” get trimmed to “Report.1”.

Next use mktemp to get the OS to create a temporary folder.  It will
guarantee a unique directory name beginning with prefix, even if parallel
processes are at work. (mktemp creates the folder and returns its name
as an atomic operation, making the rm -rf/mkdir pair unnecessary.) This
should avoid most tmp folder errors, including a duplicate "$today" string
and duplicate filenames in the same folder tree on a parallel run.