According to the Highway Code the flashing of headlights may be used to warn others of your presence. It has no other meaning attached to it. Originally used as a courtesy signal by lorry drivers, it became part of their accepted vocabulary and has since been adopted by car drivers. Some other signals have accepted meanings outside their official meaning such as giving one flash of the hazard lights to thank others for giving way. The problem with these unofficial signals is that they can easily be misinterpreted and lead to accidents.
Advice given by driving instructors is generally to avoid flashing the headlights during lessons and certainly do not use this signal on a test. If using it after the test then always make sure that two drivers cannot see the signal at the same time as they have no way of deciding who the signal is intended for. If another motorist flashes at you then always check the way is clear before proceeding. It is easy to interpret the signal as an order or request and act without checking which can bring you into conflict with other drivers.
Modern cars are fitted with a flasher switch usually located on the indicator stalk. As the switch is easily reached it is tempting to use it. The fact that the car has this function legitimises the signal and can lead to overuse. Flashing headlights is often used aggressively to demand another motorist to move out of the way. This occurs on motorways when one car closes up on another in the fast lane and then flashes to be allowed past. Used courteously it can mean that the driver intends to give way especially on crowded streets with cars parked on both sides. As the same signal can have opposite meanings it can often be difficult to distinguish between the two depending on the situation.
I have seen flashing headlights used to warn of speed cameras nearby, prompt another driver to switch on their lights and invite pedestrians to cross the road. Problems can occur when driving in darkness and the car behind goes over a speed bump. The sudden change in angle of the following headlights looks like a flash and can be worrying until you figure out what it is.
Always ask yourself what the other driver is trying to tell you before doing anything. Is the signal intended for you or is there another driver nearby? If you are about to use the signal yourself, think how it might be interpreted before using it.