William Law (1756–1823), Depute Sherriff of East Lothian