Another version of main.cpp for writing to files