Question about an expect script

I am using Expect to spawn a command that loops through a text file and runs the same command for each item in the text file.

The text file, named stat.txt looks something like this:

2007-04 alist 543
2008-07 blist 543
2008-03 xlist 345
2008-03 ylist 675
2003-03 zlist 567

The expect script looks like this:

#!/usr/bin/expect

set timeout 600
set input [open "/tmp/stat.txt" "r"]

while {[gets $input line] != -1} {

            \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#
            \# separates agency code from listname
            \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#

            set datecreated [lindex $line 0]
            set listname [lindex $line 1]
            set agency [lindex $line 2]

            set newfile $listname.members.$agency.$datecreated
            spawn /usr/local/mailman/bin/list_members -o /tmp/lists/test/$newfile $listname
            \}

close $input

---------------------------------------
The script looks at the 'listname' field in the text file, spawns the command 'list_members' for each one and creates a separate file for each, containing the email addresses of those on the list.

The script works as I want until it gets to the listname beginning with 'y'. When I run the script, I see the spawning until the end, as if it actually creates a file for each listname. However, when I do a listing on /tmp/lists/test, there are no files beyond the 'x' name. Is there a way I can see why the spawn is not working for those particular items, even though it appears that it is?

Thanks.

Try running with "expect-d" option or include "exp_internal 1" in the code. Either will turn on debugging and may give a clue as to what's happening.