Mac Terminal/iTerm history cursor problems

It is most likely because your prompt definition includes sequences that should not be counted in the length of the prompt, such as those for setting colors. These sequences should be between \[ and \] to prevent their length from being counted. Here is an example that produces an all-red prompt:

PS1='\[\033[31m\]\u@\h:\w\$\[\033[0m\]'