Create temporary file with name as suffix

This helps editors guess the filetype to properly set up their syntax
highlighting.

Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
Use TMPDIR for temporary files

Signed-off-by: Sven Wegener <sven.wegener@stealer.net>

Fall back to /tmp if copying fails for the environment variable.

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>