Try adding this code in instead…
defns = [] ### to store processed definitions
tr = Geom::Transformation.rotation(ORIGIN, X_AXIS, -90.degrees)
ent.definition.entities.grep(Sketchup::ComponentInstance).each { |e|
### grep filters for just that kind of entity
defn = e.definition
next if defns.include?(defn)
### only process ONE instance of any definition
defns << defn
### remember processed definition
defn.entities.transform_entities(tr, defn.entities.to_a)
### transform the definition's entities once...
}