First, we get the length of the list as a whole, i.e. the number of items in that list (stored in variable n). Then we remove every occurrence of that element from the list using vl-remove and take its length, which is (length (vl-remove (car a) l)). Subtracting the total length with the removed length gives you the number of occurrences of that item in the list, so if it's not equal to 1 (or greater than 1), remove that item from the list.
So:
l is stored as (1 1 2) and n as 3. Let's take the last item of the list, a=(2 (<Entity name: 8290ba00>))
(car a) = 2
(vl-remove 2 l) = (1 1)
(length (1 1)) = 2
(- n 2) --> (- 3 2) = 1
(= 1 1) = T, therefore remove item from list.
So if a=(1 (<Entity name: 8290b880>)):
(car a) = 1
(vl-remove 1 l) = (2)
(length (2)) = 1
(- n 1) --> (- 3 1) = 2
(= 2 1) = nil, therefore do not remove item from list.
By the way, debugging is something that programmers must be able to perform. You can use it in this case too even thought it doesn't yield any errors. But I have to say, that it does yield an error when I first write it up and tested it. No matter how skilled anyone is at programming (myself, Lee, and all the best programmers out there), you're bound to make a mistake at some point, especially codes with thousands of lines, so it's good to know where they occur in order to be able to fix the error. To do that, we use the debugging feature of AutoLISP. These can include step-by-step execution and variable watching. Lee Mac has provided an excellent tutorial in this link and it is VERY important for programmers to be able to use this. You can also use it in this scenario to see how the code functions.