The force introduced by the pencil is distributed amongst the tightly packed grains. The rice grains force against the pencil and the side of the coke bottle.
If you have compacted the rice enough, you should find the pencil effectively stuck (a little like when you wiggle your feet into wet sand at the beach and then try to pull your feet out again). This experiment will work with any bottle that has an opening with a smaller circumference than the bottle itself.