Used fprintf instead of printf.