A few questions about a script

Hi,

I'd like some help with the Perl script attached. It works, but I'm having problems saving the results.

The scipt loops over a number of Study Tables and in each study table it loops over the rows,

copying the structures to a new study table if some criteria (rank number and lattice energy) are fulfilled.  

The script can only run as a single instance. If I try to start a second instance of it it an other folder and on some other input files,

the second instance will fail because for some reason the folder c:\windows\TEMP\AccelrysInsertInto is created.

Why is this folder created? Can I control this behaviour and have dfferent instances of the script write to different folders, so they don't clash?

The script will crash if this folder already exists.

I've had problems with saving the results. The gateway between the client and server often fails and the new_final_structures.std file is lost.

This is extremely annoying - I keep losing data! It seems MS deletes the job and all the data when the script finished, even if the result file is not

downloaded to the client!

Is there some way to have the script explicitly save this file at some safe permanent location and exit only when this has been completed?

Is there a more graceful way to exit the script when it is completed? Now it just reaches the "last ; " statement.

I want it to save the generated file and exit in a safe and sound way.

I'd be extremely happy for any advice on how to make this script safer, faster, and less prone to data loss.