More robust to_file test

tempfile.NamedTemporaryFile was failing for me, so reimplemented the to_file test in a temp directory.  Requires a tearDown function to clean up.