The previous code didn't work because the DimLinear command has a default option "<Select Object>" that was being selected when the user pressed Enter.
If this default option didn't exist, the previous version would have worked as well.
FYI: I was not comparing two 'selected entities', I was comparing the last entity created in the drawing database before the DimLinear command is called with the last entity created after the command is called. The While condition would only continue if such entities differed, hence if the DimLinear command successfully added an entity to the drawing database.