Updated OP with an example of the format. I too would not expect such errors however I cannot think of an alternative explanation as it does not appear to be caused by any specific line or error in the content. After sorting or randomly shuffling the order of the lines within the input file, the error still occurs somewhere toward the end of the file.