Yes you must. Highway Code rule 114:
"You MUST NOT
use any lights in a way which would dazzle or cause discomfort to other road users, including pedestrians, cyclists and horse riders."
This is a “must not” (meaning it is against the law). The law in question is the Road Vehicle Lighting Regulations, s27. It says this:
27. No person shall use, or cause or permit to be used, on a road any vehicle on which any lamp, hazard warning signal device or warning beacon of a type specified in an item in column 2 of the Table below is used in a manner specified in that item in column 3.
Under Column 2 is “headlamp” and under column 3 is “(a)Used so as to cause undue dazzle or discomfort to other persons using the road.” Also under column 3 is “(b)Used so as to be lit when a vehicle is parked.” This is a particular annoyance of mine (among many) and I frequently see vehicles parked with headlights on.