It's like an exam. The markers know the answer, but you have free will to write whatever you want. They aren't going to come and tell you what to do. So, it you do something bad in life, it's not that god doesn't know about it, he/she waits until the 'exam' is over and then marks it.