This incident in Book 23 occurs because Penelope, after all she has gone through, finds it hard to believe that it is her husband who has returned. We are told she worries that it might be some God trying to trick her, so she devises her "test" of her husband's knowledge of the bed, something that only he would have known.
It is important to identify that this scene reveals Penelope's intelligence and ability to think quickly on the spot. These are qualities that we have seen before in her strategem with the burial shroud that never quite manages to be finished. It also shows us the complete suitability of Odysseus and Penelope for each other, for both are kindred spirits, united in their ability to trick and beguile and deceive. None of the suitors could ever be a suitable replacement for Odysseus in this respect, and the same is true for Circe and the other women that Odysseus has met on his travels. The fact that their wedding bed cannot be moved is therefore highly significant: their bond and marriage is so strong that nothing can shake it.
Penelope feels the need to test her husband simply because she doesn't want to make the mistake of marrying one of the suitors, not knowing that her husband has truly returned. She and Odysseus have a marriage that can withstand many tribulations. She wants to make sure that she is not being tricked. She has to come up with a plan (test) that only the "real' Odysseus would know the answer.