Corrected file writing