Your query does a cross product between the line layer and the polygon layer. If you have 1 line and 2 polygon, the line being within the first polygon, you would still get two results: one with an empty geometry (line1-polygon1) and one with a full geometry (line1-polygon2).
If your dataset is not too big, you could aggregate all the polygons into one, and then compute the difference. I would also remove the lines that are completely within the polygon, and the polygons that don't intersect with the lines
The query would be similar to the following - untested - one:
SELECT a.objectid, st_difference(a.geom, b.geom) as shape
FROM line a,
LATERAL
(SELECT ST_COLLECT(m_single.geom) geom
FROM
(SELECT (ST_DUMP(m.geom)).geom geom
FROM mesh m
WHERE ST_Intersects(a.geom,m.geom))m_single) b
WHERE ST_Within(a.geom, b.geom) = false