Heterotic modular invariants and level-rank duality