Higher-order gravitational couplings and modular forms in N = 2, D = 4 heterotic string compactifications