You open this file, but never close it. Rather than passing round an open file, you should probably try to open the file close to where it's read and close it immediately.