Problem capturing output in TCL script

I have a TCL script that logs into a switch using expect.I send a command "show port-security address" and it returns a table having a large number of rows.I need to capture this output(the table) and store it in a .txt file.
I have done this:

 
match_max 5000
set expect_out(buffer) {}
set logfile_id [open "log.txt" w]
...#code for logging in
send -i $con_id "terminal length 0\r"
expect -i $con_id -re {#}
send -i $con_id "show port-security address\r "
expect -i $con_id -re {#}
puts $logfile_id $expect_out(buffer)
flush $logfile_id
close $logfile_id

However the output is captured only partially(only the last part of the table). Where am I going wrong?