It seems that IDLE changes its current working dir to location of the script that is executed, while when running the script using cmd doesn't do that and it leaves CWD as it is.
To change current working dir to the one containing your script you can use:
import os
os.chdir(os.path.dirname(__file__))
print(os.getcwd())
Using pathlib you can get the folder in which the current file is located. __file__ is the pathname of the file from which the module was loaded.
Ref: docs