Walter Sparrow (played by Jim Carrey) is actually the fictitious Inspector Fingerling.
Walter actually wrote the story for himself to conceal the truth from everyone else. Whether he wrote it to remind himself of the truth or to tell everyone the truth is unknown.
His wife, Agatha Sparrow, gave him the book he wrote. Her intentions were not clear whether she wanted to help him remember or not.
Walter suffered from childhood trauma of his mother committing suicide followed by his father.
Walter suffered from amnesia after the murder of Laura and attempting to commit suicide.
Walter's imagination takes real people and uses their faces on the fictitious events that he wrote which is why we see his mother as the suicide blonde and why we see him as Fingerling.
Agatha was trying to help Walter in figuring out his past. However, that also returned his obsession with the numbewr 23.
Walter reveals at the end of the movie that he is a changed man and that he is not a killer. However, his obsession with the number remains.
The number 23 is not associated with anything real in the movie. It only represents Walter's obsession.
Walter confessed for his crime so that he could get a pardon and to release the psychaitrist who was innocent yet convicted with the crime of murder.
Ned, the dog that bit Walter at the beginning of the movie, actually belongs to the cemetery gardner and he wanted to lead Walter to the grave.