The Balrog, Flame of Udûn will be put on the bottom of its owner's library only if it's still on the battlefield when the ability resolves. If it leaves the battlefield before that point, it will stay in whatever zone it's in, even if it's returned to the battlefield before the ability resolves.

Artwork
Loading artwork…
The Balrog, Flame of Udûn
The Lord of the Rings: Tales of Middle-earth · #297 · EN
Nonfoil—Foil—
Card rules
Trample
When a legendary creature an opponent controls dies, put The Balrog on the bottom of its owner's library.
7/7
An evil of the Ancient World, both a shadow and a flame.
Rare · Illustrated by John Tedrick
Format legality
Brawl Legal
Commander Legal
Competitive Brawl Legal
Duel Legal
Gladiator Legal
Historic Legal
Legacy Legal
Modern Legal
Oathbreaker Legal
Penny Legal
Timeless Legal
Vintage Legal
Alchemy Not Legal
Future Not Legal
Old School Not Legal
Pauper Not Legal
Pauper Commander Not Legal
Pioneer Not Legal
PreDH Not Legal
Premodern Not Legal
Standard Not Legal
Standard Brawl Not Legal
Tlr Not Legal
Rulings
Published rulings from the downloaded Scryfall catalog. Source card record · Rules and interactions