The script above uses statically-named global variables, so if you're sending two files at once then they'll be modified by two different 'threads' at once.
You can either name the variables dynamically (using $+ and $eval or [ ]), or you can store all the information in the socket mark.
Also it would probably be better to check if your random socket name is taken before /sockaccept'ing to that name.