Out-of-universe, this was due to the existence of more than one Enterprise model, and to footage being reused:
The second configuration, used in the second pilot (and throughout the
rest of the series, due to footage being reused) was similar to the
first version, with the addition of running lights, additional
markings, and a grille pattern on the rear of each engine nacelle.
In-universe, we have the following observation:
Sometime between 2265 and 2266, the old deflector dish was replaced by
a significantly smaller model, the spikes on the Bussard collectors
were removed, a smaller bridge dome of flatter curvature was
installed, the aft caps on the warp nacelles were each equipped with a
spherical attachment, and the impulse drive now had only two large
Memory Alpha also notes that:
It is unclear whether the warp nacelles were merely modified or
As pointed out in Thaddeus' answer, there are two refits documented where modifications to the warp nacelles occurred. However, I am of the opinion that the second refit is the one that we are interested in:
A second, more extensive refit occurred at some point after her
encounter with the "galactic barrier" in 2265. It involved replacing
the bridge module, a newer, smaller deflector dish, and refinements to
her warp nacelles
In other words, the first refit happened between 2264 and 2265 but the modifications to the warp nacelles occurred between 2265 and 2266.
As to what these "ball" attachments are, here's a blueprint:
(View larger image) (Source)
You will note that the "balls" are referred to as the space matrix restoration coils. The Memory Alpha article I've linked to is pretty useless, but this site has something more to say:
While the exact function of this component is unknown, it can be
surmised that the device in some way alters the state of particles
that interact with the warp coils. It is generally believed that the
device in some way keeps the Coils in phase with the normal universe
and prevent them from slipping into subspace as a result of the
massive energy fields that they generate.
As the article above goes on to say, this is a pretty important aspect of warp travel! I can't actually find a blueprint of the Enterprise prior to its 2265 refit where the "balls" were added, but looking at the below blueprint of the Enterprise after its major refit, you can see in this aft view that it doesn't have any balls, but still incorporated the space matrix restoration coil as referred to in the Memory Alpha page because we hear it mentioned in The Motion Picture :
Furthermore, when we look at the Enterprise NX-01 blueprint, we also see that there it too had a space restoration matrix coil, meaning the Enterprise prior to refit probably also had it:
(View larger image) (Source)
The important thing to note from this image is that there are no "balls" for the space restoration matrix coil, so the parts on the rear of the nacelles on the pre-refit Enterprise were probably also part of this coil.
Consequently, I conclude that why the Enterprise got balls, in-universe, was due to improvements in the space restoration matrix coil.