fix: check return values of freopen()

Some compiles complain about not checking the return value of freopen(),
so we check it