I think you have over complicated the task, with no dwg to check if the contours are plain plines but at a elevation or are they true 3dpolylines. Using the fence ssget you get all the crossing contours then intersectwith for a point Z should be returned, a plain pline will return . I mentioned sort to make sure they are in correct order so make a list ((dist enttityname)(dist entityname)...)and sort on dist.
A pline using elev has just that a elevation property where as a 3dpoly does not have this property.