Strange bug on outputting to file.