Added file writing to program flow.