Have you looked at the copper leads? Do they look like they might have been burned? Volkswagens are notorious for electrical issues and they can short circuit. There should be three copper coated wires in the assembly, and if even one is burned it will cause the light to only work sometimes. You can check that. If they all look fine, make sure the connections are touching fully and going to the right places. It is also easy to put the metal clip part on backwards! Don't do that, I did that, it only goes one way. Hope I helped. There should be another guide on this. Maybe I will make one.
Seriously! Im an engineer and I was fighting with the headlight wondering why I couldn't loosen the latch to get it out. I apparently turned it more than 1/4. I feel like this was a bad design...