fix the TMP_DIR name with mktemp command and use .tmp extension for temporary filenames