Fixed segmentation fault. Issue was with reassigning a file pointer.