in reply to Flocking .l file instead of file to be updated

    flock SESSLOCK, 2;

Error check that flock. You don't want to go on happily thinking the file is locked if the syscall failed for some reason (out of memory? networked filesystem?). For readability, use the LOCK_EX constant from Fcntl.