fix exception when writing large output files