Move file writing section to it's own function.
Prepare for hash comparisons.