Put npm-debug.log file in the cache folder, not cwd

New version of #6181: This should prevent mishaps like #1548, while avoiding overly configurable options that make it hard to predict where the file will show up.

Fix #1584
Close #5252