... and if you are on Unix/Linux, you can do something with:
ls -1 dirname | xargs -Pnprocs
... in order to run one Perl program that, say, writes its output to a named pipe (mkfifo). (xargs takes care of all the parallelism.) Meanwhile, another process cats the input from that pipe (from whatever source) to the specified target file. Alternatively, if you have good file-locking, the Perl program briefly locks the target file before writing to it.
In this way, “the Unix way,” you use the existing facilities of the Shell to do complicated things using simple individual programs that each do only one thing.