The issue was not testing that the intersection needs to happen between the object and the light position. i.e I was raytracing past the light.
i.e the check: if(t>0.01) should instead be if(t>0.01 && t < length(object_pos - light_pos))
Or in other words, the intersection must happen between the position we are currently testing for ...
It is by design. The solution is to clone a material manually and assign to sharedMaterial array. It doesn't affect other materials.
The next code will clone only second material, do you note you can't assign a new material directly, you must modify array:
Material materials = line.sharedMaterials;
materials = Instantiate(materials);