It closes when the car is hungry and wants to take a bite out of something. More seriously, the Repair Manual (more info) explains, “The grille shutter closes when certain conditions related to the vehicle speed, engine coolant temperature, inverter coolant temperature, ambient temperature and refrigerant pressure are met.” There is a bit more information in New Car Features, under Vehicle Exterior: Exterior Panels/Trim: Grille Shutter System: Grille Shutter Control, but as with many aspects of the car’s design, the details are proprietary to Toyota and its suppliers.