The Falcon appears to contain
another copy of the Jedi sacred texts
How did they come to be located on the ship?
Did Obi-wan leave it there when he was aboard? Did Han and/or Chewie pick it up at some point? Did they know what they had?
Entirely speculative as we don't see her do it, but
The viewer is made to believe that Luke was in fact about to burn the sacred texts and that Yoda did it for him because Yoda believed it's time for Luke to move on from those ways and to realise his students will grow beyond him. Yoda almost certainly knew that Rey had taken the books given that he stopped Luke and struck the temple alight himself. Furthermore, when Luke is tempted to go in and save them Yoda causes the fire to explode outwards. It is after this point that Luke realises what he must do.
Yoda certainly knows that Rey has them since he says:
There's nothing in that library that Rey doesn't already possess
Source: just watched it again.
I think it's logical enough to assume the above given this is one of the first occurrences of books in the universe so it is unlikely there were multiple copies she'd acquired and the view at the end was a way of telling the viewer "Rey can still learn".
I believe that Rey took them from the temple after
Luke blew up the hut upon seeing Rey with Kylo Ren
There's a gap between that scene and
Rey departing on the Millenium Falcon
She knew where they were, she was determined to learn more about being a Jedi, and that Luke didn't want their contents known. And you can't tell me she didn't want to spite him, just a little.
I believe Yoda himself put them there and burned the tree to prevent Luke from discovering his subterfuge