Definitely NOT a good idea to be leaving keys in an unattended car. But I find it kind of odd that the officer decided to write a ticket when it seems like a warning would have sufficed. This is the kind of thing that reinforces the idea of there being a “ticket quota”.