Put the output file in a temporary directory.

Applies Lawrence's diff in pull request #385.