fixed the printing to file bug