in reply to how to convert lexical filehand so flock will work with it

As well as lexical filehandles, flock also shows how to die with a message which includes $! (see perlvar - Error Variables): that would be a good way for finding out what went wrong. It also has this which may be related to your problem:

"... and it requires that FILEHANDLE be open with write intent."

See also autodie.

Please also post code in <code>...</code> tags, not <pre>...</pre> tags.

-- Ken