Writing a book while completing your university studies is definitely possible.
However, it all depends on the type of student you are.
If you know how to manage your time properly, recognize your priorities and genuinely enjoy writing, then this should be an enjoyable and easy process for you.
Additionally, if you prefer your own company and dislike going out, it will help you save a lot of time and focus on writing.
Nevertheless, I would still recommend to occasionally go out, speak to new people and try different experiences. This will help you network, thus support your future career.
But please remeber to focus on your studies especially if you're studying a demanding course.
I hope I managed to help!
Best of luck,