consolidate tmpfile logic

Also use tempfile so that "/tmp" isn't hard-coded.
Merge pull request #8 from jcrobak/tmpfile-fix

consolidate tmpfile logic