Local magnetic measurements are used to quantitatively characterize heterogeneity and flux line pinning in PrFeAsO_1-y and NdFeAs(O,F) superconducting single crystals. In spite of spatial fluctuations of the critical current density on the macroscopic scale, it is shown that the major contribution comes from collective pinning of vortex lines by microscopic defects by the mean-free path fluctuation mechanism. The defect density extracted from experiment corresponds to the dopant atom density, which means that dopant atoms play an important role both in vortex pinning and in quasiparticle scattering. In the studied underdoped PrFeAsO_1-y and NdFeAs(O,F) crystals, there is a background of strong pinning, which we attribute to spatial variations of the dopant atom density on the scale of a few dozen to one hundred nm. These variations do not go beyond 5% - we therefore do not find any evidence for coexistence of the superconducting and the antiferromagnetic phase. The critical current density in sub-T fields is characterized by the presence of a peak effect, the location of which in the (B,T)-plane is consistent with an order-disorder transition of the vortex lattice.