David Gunn entered the civil service of the Transvaal Colony on 1 October 1904. By 1908 he was chief clerical assistant in the Division of Entomology of the Transvaal Department of Agriculture. When the government entomologist, C.W. Howard* resigned his post at the end of May 1908 to take up an appointment as government entomologist in Mozambique, Gunn was left to manage the affairs of the division. The next year he obtained a government scholarship to study entomology at Cornell University in the United States.
Upon his return some four years later he was appointed on 13 October 1913 as entomologist in the Division of Entomology of the Department of Agriculture of the Union of South Africa. He appears to have remained in this position for the rest of his career. During 1918-1920 he was stationed in Port Elizabeth, but during the nineteen-twenties was at the division's headquarters in Pretoria, where he did general field work and extension work with G.C. Haines*.
Even before leaving for the United States Gunn wrote a number of articles on general agricultural topics and insect pests for the Transvaal Agricultural Journal (1908/9, Vol. 7 and 1909/10, Vol. 8). Some of these were issued also as pamphlets. The topics included "Locust destruction work in the Transvaal", "Silkworm culture in the Transvaal", "The root louse of grape vines", "Some insects injurious to stored grain", "The Australian bug", "The mealie-stalk borer" and "The potato tuber moth". After his appointment as entomologist he wrote useful pamphlets and circulars that were published by the Department of Agriculture, including the following: The small cabbage moth (Plutella maculipennis Curtis) (1917), The fig and willow borer (1919), The false codling moth (1921), and Two destructive insects of carnation plants (1931).
Gunn was a foundation member of the South African Biological Society (established in 1916). He became a member of the South African Association for the Advancement of Science in 1915 and at its annual congress that year presented "Some observations on the life history of the pepper tree caterpillar, Bombycomorpha pallida Dist." However, the paper was not published.