Confusing internal memory folder structure - Galaxy S3 (I9300)
The folders you are referring to are for multi-user purposes: /emulated/legacy is a symlink pointing to the internal SD folder of the "current user", while /emulated/0 is that folder for the owner (the number at the end will be incremented for additional users created thereafter, so e.g. if you created an additional user, his place would be /emulated/1, and logged in with that user /emulated/legacy would point there).

There are sometimes issues when updating from older Android versions, where content gets duplicated from the old single-user place to /emulated/0 during the conversion process (i.e. the content is copied to the new location instead of being moved, and not deleted afterwards). As a factory-reset usually doesn't touch "user storage" (external/internal SD cards), it offers no relief to that, so you'll have to clean that up manually afterwards (if it happens).

As to your question in your comment: If this happens, it does so only when converting from "single user" to "multi-user". So your next upgrade would already start with a "multi-user ROM", which means the same issue will not happen again (as no conversion is required in this context).