It sounds like a file IO issue. The script works for me. I would check to make sure these lines have the correct permissions and paths to the files:
set fileID [open dump_hier.txt w]
# Step 1: open the layout
set layout [layout create std_.gds]
You can try the attached testcase and see if that works for you.
testcase.tar.gz 68.4 KB