Add chmod and tempdir options

by default temporary files are created 0600. before moving the file
into place, it should be possible to control the mode of the new
file.

We may want to write temporary files to /dev/shm, for example
instead of /tmp.