The flight planning systems will optimize an altitude in lieu of the dispatcher inputing one. Reasons to file different would be turbulence requiring lower or higher altitude, thunderstorms requiring higher to get above some of the weather. Flight plannign systems dont always plan for temperature and ozone limitations so sometimes you need to file lower than optimal due to those restrictions. MELs that restrict the aircraft altitude such as an AC
pack out or RVSM deferral effect the altitude filed. FL280 may be the higest you can go even though the optimal altitude is FL360.
Sometimes the flight planning system optimizes an altitude way too high or way too low of certain city pairs sometimes. It can be funny to sometimes get those calls when you miss the FL370 on a short leg or FL100 on a longer one. Most of the time, we know the routes and input a more realistic altitude but when you get busy this can sometimes be a more comical error to make.
Another thing is some flight planning systems optimize step climbs on short to medium range routes. On long hauls these step climbs are necessary but normally they are not for shorter flights and many crews ignore them anyways so I will just cruise them at the lower altitude planned by the system.
If weight and balance becomes an issue, you can file a plan lower so it can burn off more gas to get within landing weight limits.
Pilots do whatever they want with altitude. If they fly lower than planned, many airlines and FAA inspectors require they get new fuel burn numbers from dispatch. Sometimes, crews will request altitudes for better rides or to get above weather. Most of the time, pilots just ask ATC for higher or lower based on whatever altitude they want to fly. The vast majority of pilots just fly whatever altitude dispatch files.