Fix so it writes to the correct file