in reply to Suspect FH issues

even if i'm an humble monk, i can try some answer:
you are reopening your file inside the while loop. this is not correct or safe.

You have to seek the filehandle in such a case, i think, not reopen the FH.
If you really need to know the lenght of a session you can build up a hash of arrays with the session as key, start time as first index of the array and update the second element while iterating.
Something like
$sessions{$cur_id}[1] = $1 if $1 > $sessions{$cur_id}[1];
HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.