configure: more robustness with temp files and self-cleanup

The mktemp utility is much cleaner about generating filenames that are
less prone to race conditions. There is a fallback to the classic
shell script method if the utility isn't available (though it suggests
an ancient OS in use).

It also cleans itself up at the end, not leaving such files behind in
the temporary directory.