writing out correct, complete file