in reply to Order of flock and open
What if another request sneaks in between the open and flock commands?
As long as all applications that manipulate data in this file use Fcntl locking API -- flock(), fcntl(), you'll be OK. Just make sure you're checking return values of all system calls.
Ditto for unlocking and closing the handle
If you don't need the file handle after you unlock it, you can simply close() it. Perl flushes the buffers for you before unlocking the file in either case. But you can always do it yourself if you so desire.
--perlplexer