fix output file "r" -> "w"