The problem is that you are writing the ItemStack to compound, but adding item to the tag list. When you are reading from nbt, you are reading the contents of the tag list, which doesn't contain any of the ItemStacks. Changing
stack.writeToNBT(compound);
into
stack.writeToNBT(item);
in writeToNBT should fix this problem.