program will now correctly make and write to the correct file