Your understanding is more or less correct, an opening book is a large collection of positions and what are the "book moves" in that position. I don't know if engines typically choose at random if there are multiple moves in the book for a given position or if they do something more complicated, but that doesn't matter much for your question.
How can an opening book "beat" another?
It can contain better moves, and more of them, and they could even be better tailored to the specific opponent!
To figure out which is better, you let the same engine play against itself, with one side using one opening book and the other side the other. If you take care to have each book play white as often as black, you can see in the end which book had a higher score against the other book.
For instance, an opening book could contain a line somewhere that actually is not as good as the author thought at the time of putting it together, and the other book chooses to go for that position as the other side and it leads to a win for the engine.
Or one book is "done" after 15 moves after which the engine is on its own, but the other book still has several moves coming up after it on which the engine spent far more time on while creating the book than it could during the actual game.
Or the author of the opening book for engine A knows that engine B is worse at playing certain positions from the French, and he chooses to put moves into the book that causes A to go for those positions whenever it has the chance.
Or an opening book author spends days analyzing a certain position in an opening, and finally figures out that there is a way to force a good position for white there, and he adds it to the opening book. Engines with books that still allow that position to come up will have a bad time there.
And so on, opening books are in the end created by humans (with heavy use of engines) and the same arms race is going on there as between top human players.