New Insights into the Stellar Initial Mass Function: the Interplay between Filaments, Magnetic Fields, and Protostellar Accretion