Please read this comment about how folder display node works
Is it possible that when you paste the code in the Python console you already clicked the show/hide of the folder in the Data module, but when you had done this from your module you hadn’t?
By the way please use the latest Slicer, we cannot really help with old versions. 5.6.2 is a year and a half old now, and there have been quite a lot of changes since then.