The command that you are using here is an fs command of Hadoop. An fs command refers to any file system, it could be either HDFS or local. That is why, you are getting an error because -safemode is not an argument of Hadoop fs(file system). Since, safenode is a command of Hadoop dfsadmin, try running your command in dfsadmin, so it directly refers to HDFS file system, not your local system.
hdfs dfsadmin -safemode leave
You can check out the following video you have any doubts regarding the same: