Yes, a tempfile might be a good idea.

If you want to make another pull request using http://www.ruby-doc.org/stdlib-1.9.3/libdoc/tempfile/rdoc/Tempfile.html I will be happy to merge it.