Write_file now handles the opening of the file
Updated write_file()'s definition
Write file now also closes the file
Write_file now handles opening and closing of outfile