If you're only looking to list the duplicate text items at the command-line, the code can be simplified greatly, e.g.:
(defun c:dupetext ( / d i l s x )
(if (setq s (ssget "_X" (list '(0 . "TEXT") (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model")))))
(repeat (setq i (sslength s))
(setq x (cdr (assoc 1 (entget (ssname s (setq i (1- i)))))))
(cond
( (not (member x l)) (setq l (cons x l)))
( (not (member x d)) (setq d (cons x d)) (print x))
)
)
)
(princ)
)