Changed the printf to fprintf