Fix TMP file and andd main() function.

Always use `mktemp`. Please spare me the `/tmp/$$` stuff or other
insecure alternative to temporary file creations, use only `mktemp`