my suspicion is that you are losing track of how many times you have opened / closed the file pointer, and that you are trying to read a pointer that is not opened.or close a pointer that is not opened.
this would explain why you're getting a segmentation fault. this is a common error that happens when you start using globals inside subroutines, it's just generally bad practice for that reason.
of course i could be wrong .... buti don't have anything else to go on, since you've only given subroutine.
it definitely is very suspicious though. i would rewrite the program to not use global file pointers.