Another solution, and it is a bit bulkier than the timehighres-PID idea (which is a good one) is just to have a process that sits on a socket and hands out incremental numbers. Then you can launch as many of your file generating scripts in parallel as you want, they will each always be handed a unique number by your script.