The reason we use less flaps if departing heavy and/or at a high altitude density airport, is for better climb performance during the second segment.
We always plan for worse case scenario. For a twin engine jet the most critical segment is the 2nd segment. This is the point between when the landing gear is fully retracted and reaching the engine out clean up altitude (usually between 400-1000'agl or obstacle clearance alt). Our performance numbers (Rwy limit weights and climb limit weights) allow for a minimum of a 2.4% climb gradient in the second segment in the event of an engine failure before V2.
Less flaps allow for higher climb limit weights due to less drag (this is usually the limiting factor over Rwy limit weights). If the rwy is short we may use more flaps but at the expense of 2nd segment penalties. It's all a trade off and is sometimes a balancing act using performance charts between flap and power settings, rwy and climb limit weight limits.