Agatha buys the book (titled The Number 23 written by Topsy Kretts) for her husband Walter as a birthday present. Why does she choose this book? Is it a coincidence? Doesn't she know about the past of her husband?
She merely bought the book for him as she felt he would be very interested in it, having just skimmed through it herself. She did not (nor did Walter, at this point) know anything about his past or that he actually wrote the book.
It is essentially a
plot device coincidence.