Reopen file instead of using freopen