Create a GuestBook script that stores visitor names and email addresses in a text file. Include functionality to view guest book and prevent the same username being entered twice. Also, include code that sorts the guest book by name and deletes duplicates.