Measurement of relative branching fractions of B decays to ψ(2S) and J/ψ mesons