replace print with fprintf