I’d be tempted to use Ruby’s existing [tempfile](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/tempfile/rdoc/Tempfile.html) mechanism for this, rather than coming up with creative ways of generating unique filenames ourselves.