problem is here:
polyCube -n $name;
Well maya doesn't actually work that way, see maya at its own discretion WILL RENAME YOUR cube since there can not ever be a naming clash. So what you have to do is actually catch what maya named the cube and act on that.
However your code is a bit inefficient there's actually a easier way to accomplish the same thing. And that to just create one object and duplicate input network 100 times.
About your expression:
you should avoid using mel inside expressions, its going to get you into BIG PROBLEMS in the long run. Its inefficient and subverts how the dag is supposed to work. The time you save now is insignificant to the time you loose when you hit the wall with this method and cant hack it what the showe comes to push because you TOUGHT you had things solved. So no getAttr except under very controlled environments. Here you dont need it for anything.