The thing you needed to find is why I answered "TOO BAD", not why your script doesn't work.
As an hint: "TOO BAD" is my standard reply when a question can't be answered because it lacks relevant informations, or when it's about an outdated and unmaintained ns-3 version. or both at the same time.
Your original post perfectly matches all the criteria for a "TOO BAD".
Feel free to amend the question by:
1) upgrade to the latest ns-3,
2) provide exact and reproducible steps to show the issue. Adding the scrip as an attachment is useful.
Point 1 is to avoid bugs already fixed, and/or the hassle of downloading and installing unsupported ns-3 versions.
Point 2 is to avoid that we have to use our (limited) time to build a script similar to the one giving you issues, maybe just to find out that it works for us.
T.