Pencils are made of graphite, and when you draw the pencil across the paper, some graphite particles get stuck on the paper fibers, leaving behind the marks and letters you just wrote.
When a traditional rubber eraser is used to eliminate these graphite marks, they are being rubbed over the surface to create friction, which heats up the rubber molecules, making them sticky. These sticky molecules then pluck out those graphite particles that are on the very top layers of the paper fibers.
Modern erasers are almost always made from petroleum-based synthetic rubber compounds, typically polyvinyl chloride Because the particles that make up an eraser are stickier than paper, those graphite particles get stuck to the eraser instead.
More expensive erasers use vinyl and plastic materials. These materials are used because they are even stickier than paper fibers, and are therefore able to lift graphite particles onto them more easily.