Writing a book for others is not illegal in and of itself. Writing something for someone else and being paid for it is a common practice in many industries, and it is considered a legitimate form of freelance work.