It would be in the (setq set2 (ssget "x" (list (assoc 11 list2)))) portion. You're filtering here for X, Y & Z at the same time.
To have it ignore the X & Y, you can add it like so:(setq set2 (ssget "x" (list '(-4 . "*,*,=") (assoc 11 list2))))
BTW, why code 11? Why not 10? 11 only exists if the text isn't justified with normal Left.
And also, a possible problem you might run into is the restriction on active selection sets. You'll need to set the variable to nil and run gc to clear the selection sets as they're created within loops - so you can have many 1000's of selection sets - this will error.