Moved file writing out into its own class.