Just write to file, print it out after

Refactored to be less indented
Added test