in reply to Re^4: Bad file descriptor error
in thread Bad file descriptor error

You could have found that yourself if you printed out the lines as your program went through them, or if you added the text of the line to your error message.