I discovered that I can duplicate the error by re-submitting the form while the file is uploading. So how do you get users to not do that?
I tried showing a page that does an ns_write "Please wait...", and then does the processing. BUT that page does NOT show up on the browser until the processing is finished! Only if I then refresh that page, does it do what I wanted: it prints the words, THEN performs the processing, and then prints the next words. So how do I make it ALWAYS flush the words before doing the processing???