This idea comes from Malachi 3:16.
Then those who feared the Lord spoke with one another. The Lord paid attention and heard them, and a book of remembrance was written before him of those who feared the Lord and esteemed his name
It is not so much what we do that is written in this book, as who we are.
A similar idea is the “book of life” mentioned in Philippians 4:3 and in several places in Revelation. See Rev 20:12-15 for example.
I think these books are symbolic rather than literal. The idea is that God knows who you are and what sort of person you are. If your name is in his book of life, then you have a place in his kingdom.