No one knows the exact reason why so many people suffer from grinding teeth at night. There are many factors which may contribute to it including stress and teeth misalignment.
The question is whether your diet affects your teeth grinding and whether changing the food you eat can help solve the problem. If you suffer from bruxism (and even if you don't), you should never chew on pencils or other things that are not food. The teeth in your mouth are meant for food items and things like ice do damage to them. If you want to stop grinding teeth you should not be chewing gum throughout the day as that works the jaw muscles and they get more used to clenching and tightening up.
It is also a good idea to avoid all hard foods like candy and nuts and you should make sure to drink a lot of water every day. Caffeine is another thing that should be avoided so you must limit your intake of all the colas, gourmet coffee, tea, and chocolate.
Changing your diet in these ways can be used to reduce your teeth grinding but probably not eliminate it. There are really no foods that are more prone to "make you grind your teeth" but some foods such as coke and chocolate do make it more easy for you to do. You diet might be a contributing factor towards your grinding teeth but it is not the cure.