Question: Why would Sam and his friends go to the library?
Answer: It was the closest building they could access. While the smarter move would have been to just go back to JD's apartment (which Brian and Laura suggest) it may have been too far a walk to get out of the flooding streets.
Why did they burn the books and not the wooden shelves that the books were on?
As for burning books rather than shelves, it was just easier. They would have had to expend more energy to break down the shelves into manageable size.
They burn books instead of the wooden shelves because burning books is a quicker and more efficient way to generate heat in a desperate situation, as the paper readily catches fire and produces a substantial amount of heat compared to solid wood, which might take longer to burn properly.
Answer: Possibly because it was the closest building with height to it as they are about to be hit by a gigantic wave of water. There was no snow yet, so I don't believe burning books or snow was on anybody's mind yet. It turned out to be a great idea as snow soon starts to fall and those books were literally a life saver.
Susan D. Santos