As far as I know, Dr Hornbook was written before Tam o' Shanter. Hornbook has been dated as 1785, and published in 1787, and Tam was not published until 1791. Dr Hornbook was John Wilson, schoolmaster in Tarbolton who supplemented his income by pracising amateur medicine, pretty unsuccessfully, according to Burns. In one way, the poem makes Wilson a figure of ridicule, and in another it highlights the lack of access to medical services (such as they were in these days) in these rural communities. It seems that the poem was prompted by Burns having heard him boasting about his abilities in the medical field. It is also recorded that Wilson did not hold this against Burns.
Holy Willie's Prayer is a masterpiece on the nature of hypocrisy and ridicule of Kirk elder Willie Fisher. I think that one of the reasons that Burns' poetry can strike a chord today is that so much of his writing, humour and satire is on subjects relating to human nature, which remains the same, even as times change. The expression "Holy Willie" has even come into usage to describe certain types of individual, and we can all think on people to whom we would apply this title.
It seems that Holy Willie did eventually get his desserts. He was found frozen to death in a ditch in 1809, it is assumed through drink.
Merda taurorum animas conturbit. Quidquid latine dictum sit, altum videtur