Fix error handlings for fprintf() and fputs() to file.