in reply to How do I change directory to root directory

You're getting the error because there's no subdirectory named "mydirectory" in the subdirectory in which the script runs. You could use an absolute directory name, like chdir("/home/ikegami/mydirectory/") for example.