I always think that Tom was part of Eru's creation of Arda itself, separate to the Valar, the Elves and Men. And put there by Tolkien to confound us! It would be very easy to have Eru create an ordered world with all the necessary gods and races in their correct place but Tolkien doesn't let Eru do that. Instead, Eru really
is omnipotent and unknowable and lets beings like Tom and Ungoliant into his creation - as a result confounding all the readers!
We can only theorise
My theory on Ungoliant is that she isn't evil at all. She is simply an 'absence of light' or Un- Light. If Light is seen as somehow 'holy' in Tolkien's creation then Ungoliant is an absence of Light. She feeds on it like a black hole, but she isn't evil as she is part of what Eru either sent into the world or caused to happen during its creation.