in reply to CGI, write to file

Given that you're not really saying what the problem looks like ("doesn't work" isn't a problem - it works fine, just not the way you expected it to), I'm going to hazard a guess and say that you're expecting appending to a file, and wondering why the file only ever has one name in it. Try using:

open(TMP, ">>textfile");
Or, if that file simply doesn't exist, try:
open(TMP, ">>/tmp/textfile");