in reply to CGI filename race

The most straightforward way would be to create an open filehandle in exclusive mode and retry with another name if that fails. You can't get it to work correctly testing on filenames directly - unless you implement a separate locking mechanism that'll probably just complicate matters.

See sysopen and perlopentut. Also File::Temp for an implementation of that idea.