Gale kept a diary of items related to the construction of the meth lab operation he performed for Gus.
I didn't know this, but the Breaking Bad blog says the lab was originally for Gale alone to provide meth for Gus, possibly also for the Croatians, where the quality was expected to be low (Lydia's explanation to Walt about Gus' plans for Europe). Walt's consistent high quality product made him a better candidate for the job, and Gale relegated to backup.
This lab was presented as a gift to Walt and Pinkman when Walt agreed to work for Gus. It replaced their travelling lab - the RV. The notebook was found during the investigation of Gale's murder.
Gale would sprinkle commentary, scientific formulas, equipment specifications, etc. throughout the notebook. The notebook was dedicated to WW, which Walt told Hank could be to Walt Whitman, since he recognized a bit of poetry.
Gale must have also dedicated to Walt, a copy of Whitman's poems. The handwriting was similar and contained a similar feeling. Hank probably recognized the handwriting, and possibly just a loose connection to the poetry. The inscription "W.W." stood out for him enough for him to recall the earlier conversation with his brother-in-law where Hank intimated, in jest, the possibility of initials WW meant Walter White.
Here's an image of the Leaves of Grass inscription.
You can see the other inscription by opening the Notebook at AMCTV.
UPDATE: During a rewatch of season 5, Hazard Pay (episode 3) is the first episode where I noticed the copy of Leaves of Grass which is later revealed to be Gale's inscribed copy to Walt. Walt unpacks it, studies its cover, and chuckles before he places it very conspicuously on his nightstand as he moves back from the apartment to their house together.