In Terminal, when the the “cd” command is called, libwww-perl's “head” command is also executed
I am going to assume you are using bash.

So in that case when you just type cd it should be running the bash built-in. This is what has the problem.

To confirm this try using the external version - at the command prompt type /usr/bin/cd and you should go to your home directory with no problems.

Now let's check what the other cd might be up to.

type -a cd should give us

cd is a shell builtin
cd is /usr/bin/cd


which head should give us /usr/bin/head

alias might give us a long list but nothing pointing towards an alias for cd

The CD environment variables should have sane entries:

CDARGS_NODUPS=1
CDARGS_SORT=0
CDPATH='.:~:~/bin:~/dev:/usr:/'


The same with:

PROMPT_COMMAND='history -a; history -n; printf "\e]1;${PWD}\a"'
PS1='\[\033[34m\]\h:\W \u$\[\033[0m\] '
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor


If all that is OK then my money would be on cd being redefined by a builtin function that has gone pear shaped. At the command line set | less will allow you to page through a dump of all your shell variables, aliases and functions. If you type / you can search through the file for cd (notice the space) and see if that is happening.

Once you have discovered that "someone" - in your case rvm - is defining a shell function called cd then you can either uninstall the culprit or find where it does the nasty work and change the name of the function to something like 'rcd' instead of 'cd'. As the shell function is listed first in the output of type the builtin cd is ignored except where it is getting called by the function (that's what the builtin cd in the function definition is doing - calling the builtin version).

I'd almost guarantee that the function is defined in /Users/user/.rvm/scripts/rvm.

I'd start by uninstalling rvm and then reinstall to see if that fixes it. Are you installing it using MacPorts or Homebrew?