This needs to be moved inside the if block, otherwise if the current resource is not enabled, you'll skip constructing the "contents" array (the whole block 157-170 is not executed) and then you'll log on line 172, and then you'll hit these lines and write out nothing to /etc/filesystems.