Yes you can, absolutely write a book without ever publishing it. Lots of folks do it for personal fulfilment, kind of quiet learning, or to keep memories safe. If later you decide to share what you wrote, then checking out book publishers and getting a handle on how the whole publishing process works can really help. It means you can make a better call , that actually fits your goals.