Difference boolean modifier acts like union but only on a specific object
The reason, that you have different result in viewport and render is because you have different subdivision settings for render and viewport. 

The BMesh solver for booleans works faster, but in tiny geometry it can make a mistakes from time to time. In your case it makes errors in tiny lines here:



So you can swich to Carve solver, it works slower but never makes a mistakes in correct geometry:



But maybe you haven't this selector (it depends of version of blender), so in this situation you can change overlap Threshold to like 0.1µm to make them more accurate.

But instead of this you can just make gaps a little bit thicker, or use a texture.