Address issue #76 - check error return codes

Checking error return codes in fprintf and a malloc.