removing artifacts in Shadowmap adds some extra shadows

I am trying to implement shadowmap in opengl. I am having some artifacts which i am supposed to have. But while trying to remove that i get some extra shadows

vec4 shadowCoordinateWdivide = shadowCoord / shadowCoord.w ;
    //shadowCoordinateWdivide.z += 0.005;
    float distanceFromLight = texture2D(shadowMap, shadowCoordinateWdivide.xy).z;
    float shadow = 1.0;
    if (shadowCoord.w > 0.0)
        shadow = distanceFromLight < shadowCoordinateWdivide.z ? 0.5 : 1.0 ;
    gl_FragColor *= shadow;

adding the line

shadowCoordinateWdivide.z += 0.005;

adds some extra shadows for the planes behind.

Using an offset to prevent depth fighting is a fudge. The actual offset needs to be just enough to prevent depth fighting but not so much as to extend the light/shadow boundary into other geometry. It helps if you can minimise the ratio of the far plane to the near plane when rendering the shadow map, i.e. move the near plane as far from the light as possible without it touching the geometry. If you can’t manage that, consider using a linear depth buffer.