Multi-headed trolls do not appear elsewhere in Tolkien's works, but they appear in other stories Tolkien would have been familiar with, most notably "Soria Moria Castle" from Andrew Lang's The Red Fairy Book.
In The History of the Hobbit, John Rateliff notes about this line (which in the original draft read "Yes I am afraid trolls behave like that, even those with one head only.")
Trolls with multiple heads appear in many stories, perhaps the most famous of which is Dasent’s ‘Soria Moria Castle’, where the hero must confront and defeat first a three-headed troll, then a six-headed troll, and finally a nine-headed troll (East o’ the Sun & West o’ the Moon [1888], pages 397–401). This same story might have contributed to the naming of Moria; see Tolkien’s letter to Mr. Rang, August 1967; Letters p. 384.
The History of the Hobbit - The Second Phase, II. Trolls
As Rateliff points out, Tolkien refers to this story as a possible source for the sound sequence he used when naming Moria.
In fact [Moria] first appeared in The Hobbit chap. 1. It was there, as I remember, a casual ‘echo’ of Soria Moria Castle in one of the Scandinavian tales translated by Dasent. (The tale had no interest for me: I had already forgotten it and have never since looked at it. It was thus merely the source of the sound-sequence moria, which might have been found or composed elsewhere.) I liked the sound-sequence; it alliterated with ‘mines’, and it connected itself with the MOR element in my linguistic construction.
Letter to Mr. Rang, August 1967, The Letters of JRR Tolkien #297
In The Annotated Hobbit, Douglas Anderson makes a similar observation, and also points out that this story along with an illustration of such a troll was included in one of Tolkien's favorite children's books.
Often in fairy stories, trolls are depicted as having many heads. The illustration above, by Lancelot Speed (1860-1931), is of the troll in the story
“Soria Moria Castle” in The Red Fairy Book (1890), edited by Andrew Lang. The Red Fairy Book also contains one of Tolkien’s favorite childhood stories, that
of Sigurd and the dragon Fafnir.
The Annotated Hobbit
It is thus likely that Tolkien was trying to reference other fairy stories that his children would have been familiar with.