Change main script chdir logic