ENH: support file names in `to_file`
TST: Add `__main__` to test file.
TST: Test to_file and from_file both using filenames and file like objects.
MAINT: reorder imports
TST: test file names in to_file method