Use tempfile() instead of /tmp/

Fixes #858.